package com.lecture.junit.tdd.example;

/**
 * User: Yury
 */
public abstract class LoginServiceState {


    public void login(IAccount acc, String password, LoginService context) throws AccountNotFoundException, AccountAlreadyRevokedException {

        if (acc.passwordMatches(password)) {
            if (acc.isRevoked()) {
                throw new AccountAlreadyRevokedException("Account is already revoked");
            }
            acc.setLoggedIn(true);
            context.setState(acc.getUserName(), new FirstFailedAttempt());
        } else {
            dealWithFailedAttempt(acc, context);
        }
    }

    protected abstract void dealWithFailedAttempt(IAccount acc, LoginService context);
}
